﻿@model ForgotPasswordViewModel    
<div class="card">
    <div class="card-header text-center">
        忘记密码
    </div>
    <div class="card-body">
        <div class="pt-3">
            <form id="formForgotPassword">
                @Html.HiddenFor(m => m.UserId)
                <div class="form-group">
                    <label for="">验证码</label> @Html.ValidationMessageFor(m => m.VerificationCode)
                    <div class="row">
                        <div class="col-md-4 float-left">
                            @Html.TextBoxFor(m => m.VerificationCode, new {@class = "form-control", maxlength = 6, placeholder = "请输入验证码"})
                        </div>
                        <div class="col-md-4 float-right">
                            <button id="btnSendVerificationCode" type="button" class="btn btn-success">获取验证码</button>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="">新密码</label> @Html.ValidationMessageFor(m => m.NewPassword)
                    @Html.PasswordFor(m => m.NewPassword, new {@class = "form-control", placeholder = "请输入新密码"})
                </div>
                <div class="form-group">
                    <label for="">确认密码</label> @Html.ValidationMessageFor(m => m.ConfirmPassword)
                    @Html.PasswordFor(m => m.ConfirmPassword, new {@class = "form-control", placeholder = "请输入确认密码"})
                </div>
                <div class="form-group">
                    <button id="btnSubmitForgotPassword" type="button" class="btn btn-primary">重置密码</button>
                    <a href="/manage" class="btn btn-secondary">取消</a>
                </div>
            </form>
        </div>

    </div>
</div>
@await Html.PartialAsync("~/Views/Shared/resultModal.cshtml")

@section Scripts{
    <script >
jQuery(function ($){
    $("#btnSendVerificationCode").click(function (){
        $.get("/SendVerificationCode",function (data){
            $("#resultModal .modal-body").html(data.msg);
            $("#resultModal").modal("show");
        });
    });
    $("#btnSubmitForgotPassword").click(function(e){
         e.preventDefault();
        if ($("#formForgotPassword").valid()) {
            var _data = {
                UserId: $("#UserId").val(),
                VerificationCode: $("#VerificationCode").val(),
                NewPassword: $("#NewPassword").val(),
                ConfirmPassword: $("#ConfirmPassword").val()
            };
            $.ajax({
                type: 'POST',
                url: '/ForgotPassword',
                contentType: 'application/json; charset=UTF-8',
                data: JSON.stringify(_data),
                success: function (data) {
                    $("#resultModal .modal-body").html(data.msg);
                    $("#resultModal").modal("show");
                    $("#formForgotPassword").get(0).reset();
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $("#resultModal .modal-body").html("密码修改失败");
                    $("#resultModal").modal("show");
                }
            });
        }
    });
    })  ;
    </script>
}